package com.bailian.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bailian.common.annotation.Log;
import com.bailian.common.core.controller.BaseController;
import com.bailian.common.core.domain.AjaxResult;
import com.bailian.common.enums.BusinessType;
import com.bailian.system.domain.BlNews;
import com.bailian.system.service.IBlNewsService;
import com.bailian.common.utils.poi.ExcelUtil;
import com.bailian.common.core.page.TableDataInfo;

/**
 * 企业资讯Controller
 * 
 * @author bailian
 * @date 2025-08-04
 */
@RestController
@RequestMapping("/system/news")
public class BlNewsController extends BaseController
{
    @Autowired
    private IBlNewsService blNewsService;

    /**
     * 查询企业资讯列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlNews blNews)
    {
        startPage();
        List<BlNews> list = blNewsService.selectBlNewsList(blNews);
        return getDataTable(list);
    }

    /**
     * 导出企业资讯列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:export')")
    @Log(title = "企业资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlNews blNews)
    {
        List<BlNews> list = blNewsService.selectBlNewsList(blNews);
        ExcelUtil<BlNews> util = new ExcelUtil<BlNews>(BlNews.class);
        util.exportExcel(response, list, "企业资讯数据");
    }

    /**
     * 获取企业资讯详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(blNewsService.selectBlNewsById(id));
    }

    /**
     * 新增企业资讯
     */
    @PreAuthorize("@ss.hasPermi('system:news:add')")
    @Log(title = "企业资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestParam(name = "id",required = false) Long id, @RequestParam(name = "content",required = false) String content, @RequestParam(name = "title",required = true) String title, @RequestParam(name = "typeId",required = true) String typeId, @RequestParam(name = "desc",required = true) String desc, @RequestParam(name = "linkUrl",required = false) String linkUrl, @RequestParam(name = "thumbnailUrl",required = true) String thumbnailUrl)
    {
        BlNews blNews = new BlNews();
        blNews.setId(id);
        blNews.setContent(content);
        blNews.setTitle(title);
        blNews.setTypeId(typeId);
        blNews.setDesc(desc);
        blNews.setLinkUrl(linkUrl);
        blNews.setThumbnailUrl(thumbnailUrl);
        return toAjax(blNewsService.insertBlNews(blNews));
    }

    /**
     * 修改企业资讯
     */
    @PreAuthorize("@ss.hasPermi('system:news:edit')")
    @Log(title = "企业资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestParam(name = "id",required = true) Long id, @RequestParam(name = "content",required = false) String content, @RequestParam(name = "title",required = true) String title, @RequestParam(name = "typeId",required = true) String typeId, @RequestParam(name = "desc",required = true) String desc, @RequestParam(name = "linkUrl",required = false) String linkUrl, @RequestParam(name = "thumbnailUrl",required = true) String thumbnailUrl)
    {
        BlNews blNews = new BlNews();
        blNews.setId(id);
        blNews.setContent(content);
        blNews.setTitle(title);
        blNews.setTypeId(typeId);
        blNews.setDesc(desc);
        blNews.setLinkUrl(linkUrl);
        blNews.setThumbnailUrl(thumbnailUrl);
        return toAjax(blNewsService.updateBlNews(blNews));
    }

    /**
     * 删除企业资讯
     */
    @PreAuthorize("@ss.hasPermi('system:news:remove')")
    @Log(title = "企业资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blNewsService.deleteBlNewsByIds(ids));
    }
}
